import { Inject, Injectable } from "@nestjs/common";
import { CreateRecordDto } from "./dto/create-record.dto";
import { UpdateRecordDto } from "./dto/update-record.dto";
import { PrismaService } from "@/common/prisma/prisma.service";
import { handleError } from "@/utils/handle.error";
import { LoggerService } from "@/common/logger/logger.service";

@Injectable()
export class RecordService {
	@Inject(LoggerService)
	private readonly logger: LoggerService;

	@Inject(PrismaService)
	private readonly prisma: PrismaService;

	async create(createRecordDto: CreateRecordDto) {
		try {
			const record = await this.prisma.record.create({
				data: createRecordDto,
				select: {
					id: true,
				},
			});
			return record.id;
		} catch (error) {
			handleError(this.logger, error, {
				common: "创建失败",
			});
		}
	}

	async getListById(userId: number) {
		try {
			const list = await this.prisma.record.findMany({
				where: {
					userId,
				},
				include: {
					user: true,
				},
			});
			return list;
		} catch (error) {
			handleError(this.logger, error, {
				common: "获取失败",
			});
		}
	}
}
